#include<bits/stdc++.h>
#define MAXN 100005
#define MAXM 100005
#define MAXP 1000005
using namespace std;
int p[MAXM];
int cnt[MAXP];
bool flag[MAXN];
vector < pair<int,bool> > res[MAXP];
vector <int> num[MAXN];
pair <int,int> pos[MAXN];

int main()
{

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    int t;
    scanf("%d",&t);

    for(int i = 1;i <= t;i++)
    {
        int n,m,l,v;
        scanf("%d %d %d %d",&n,&m,&l,&v);

        for(int j = 1;j <= n;j++)
        {
            int d,v0,a;
            scanf("%d %d %d",&d,&v0,&a);

            if(v0 <= v && a <= 0) {pos[j] = {l + 1,l + 1};}
            if(v0 <= v && a > 0) {pos[j] = {d + (int)((v * v - v0 * v0) / 2.0 / a + 1),l};}
            if(v0 > v && a < 0) {pos[j] = {d,d + (int)ceil((v * v - v0 * v0) / 2.0 / a - 1)};}
            if(v0 > v && a >= 0) {pos[j] = {d,l};}

        }

        int tot = 0;

        for(int j = 1;j <= m;j++)
        {
            scanf("%d",&p[j]);

            for(int k = 1;k <= n;k++)
            {

                if(p[j] >= pos[k].first && p[j] <= pos[k].second)
                {
                    tot = flag[k] ? tot : tot + 1;
                    flag[k] = 1;
                    cnt[p[j]]++;
                    res[p[j]].push_back({k,0});
                    num[k].push_back(p[j]);
                }

            }

        }

        int sum = 0;

        for(;;)
        {
            int maximum = 0;
            int maxpos;

            for(int j = 1;j <= m;j++)
            {
                maxpos = maximum < cnt[p[j]] ? j : maxpos;
                maximum = max(maximum,cnt[p[j]]);
            }

            if(!maximum) {break;}

            for(int j = 0;j < res[p[maxpos]].size();j++)
            {

                if(res[p[maxpos]][j].second) {continue;}

                for(int k = 0;k < num[res[p[maxpos]][j].first].size();k++)
                {

                    for(int q = 0;q < res[num[res[p[maxpos]][j].first][k]].size();q++)
                    {

                        if(res[num[res[p[maxpos]][j].first][k]][q].second && res[num[res[p[maxpos]][j].first][k]][q].first == res[p[maxpos]][j].first) {break;}

                        if(!res[num[res[p[maxpos]][j].first][k]][q].second && res[num[res[p[maxpos]][j].first][k]][q].first == res[p[maxpos]][j].first)
                        {
                            res[num[res[p[maxpos]][j].first][k]][q].second = 1;
                            cnt[num[res[p[maxpos]][j].first][k]]--;
                            break;
                        }

                    }

                }

            }

            sum++;
        }

        for(int j = 1;j <= n;j++)
        {
            flag[j] = 0;
            pos[j] = {0,0};
            num[j].clear();
        }

        for(int j = 1;j <= m;j++)
        {
            p[j] = 0;
            cnt[p[j]] = 0;
            res[p[j]].clear();
        }

        printf("%d %d\n",tot,m - sum);
    }

    fclose(stdin);
    fclose(stdout);

    return 0;
}
